package com.tg.paw.common.util;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;

/**
 * @author Rubble
 * @date 2020/10/21
 */
@Data
public class CommonPageResult extends CommonResult {

    private int total;
    private int pageSize;
    private int current;
    private int totalPage;

    /**
     * 分页列表
     * @param page 获取的数据
     */
    public static CommonPageResult pageResult(IPage page) {
        CommonPageResult instance = new CommonPageResult();
        instance.code = CommonResult.SUCCESS;
        instance.msg = "操作成功";
        instance.pageSize = (int) page.getSize();
        instance.current = (int) page.getCurrent();
        instance.total = (int) page.getTotal();
        instance.totalPage = (int) page.getPages();
        instance.data = page.getRecords();

        return instance;
    }
}
